home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / HENSA / MATHS / PLPLOT / PLPLOT.ZIP / sys / dos / msc / mscvga.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-25  |  9.4 KB  |  345 lines

  1. /* ///////////////////////////////////////////////////////////////////
  2. //  name change from <dosvga.c> since the driver is microsoft specific
  3. //
  4. //  File:       mscvga.c                                         [msc]
  5. //
  6. //  Descript:   the VGA display driver for DOS or OS/2 DOS mode
  7. //
  8. //  Library:    plplot
  9. //
  10. //  Requires:   Miscrosoft C 7.0 (6.0 ?)
  11. //
  12. //  Public:     plD_init_vga()
  13. //              plD_line_vga()
  14. //              plD_polyline_vga()
  15. //              plD_eop_vga()
  16. //              plD_bop_vga()
  17. //              plD_tidy_vga()
  18. //              plD_state_vga()
  19. //              plD_esc_vga()
  20. //
  21. //              pldummy_mscvga()
  22. //
  23. //  Private:    pause()
  24. //              vga_graphics()
  25. //              vga_text()
  26. //
  27. //  Notes:      ---
  28. //
  29. //  Revisions:
  30. //  13 Apr 94   mjo     modified to use graphics calls for C7
  31. //                      "cleaned up" polyline routine
  32. //  -- --- --   ---     ---
  33. //  below is the original header
  34. //
  35. // Revision 1.11  1993/07/31  07:56:28  mjl
  36. // Several driver functions consolidated, for all drivers.  The width and color
  37. // commands are now part of a more general "state" command.  The text and
  38. // graph commands used for switching between modes is now handled by the
  39. // escape function (very few drivers require it).  The device-specific PLDev
  40. // structure is now malloc'ed for each driver that requires it, and freed when
  41. // the stream is terminated.
  42. //
  43. // Revision 1.10  1993/07/16  22:11:14  mjl
  44. // Eliminated low-level coordinate scaling; now done by driver interface.
  45. //
  46. // Revision 1.9  1993/07/01  21:59:32  mjl
  47. // Changed all plplot source files to include plplotP.h (private) rather than
  48. // plplot.h.  Rationalized namespace -- all externally-visible plplot functions
  49. // now start with "pl"; device driver functions start with "plD_".
  50. //
  51. /////////
  52. //      dosvga.c
  53. //      Geoffrey Furnish
  54. //      5-1-91
  55. //
  56. //      This file constitutes the driver for a VGA display under DOS or
  57. //      OS/2 DOS mode.  It is based on the xterm driver.
  58. //
  59. //      NOTE:
  60. //      This file is intended to be compiled with Microsoft C or QuickC.
  61. //      I use graphics functions from their library
  62. //
  63. //      The Geoffrey Furnish Standard Disclaimer:
  64. //      "I hate any C compiler that isn't ANSI compliant, and I refuse to waste
  65. //      my time trying to support such gaobage.  If you can't compile with an
  66. //      ANSI compiler, then don't expect this to work.  No appologies,
  67. //      now or ever."
  68. //
  69. /////////////////////////////////////////////////////////////////// */
  70.  
  71. #if defined (_MSC_VER) && defined(MSDOS)  /* Only compile for DOS and Microsoft */
  72.  
  73. #include "plplotP.h"
  74. #include <stdio.h>
  75. #include <stdlib.h>
  76. #include "drivers.h"
  77. #include <graph.h>
  78. #include <conio.h>
  79.  
  80. static void    pause        (PLStream *);
  81. static void     vga_text        (PLStream *);
  82. static void     vga_graphics    (PLStream *);
  83.  
  84. #ifndef TRUE
  85.   #define TRUE 1                /* define truth */
  86.   #define FALSE 0
  87. #endif
  88.  
  89. /* the initialization values are _only_ for reference - not used */
  90. static short
  91.     isPageDirty = FALSE,
  92.     DetectedVideoMode = _VRES16COLOR,
  93.     vgaXres = 639,
  94.     vgaYres = 479;
  95.  
  96. /*----------------------------------------------------------------------*\
  97. * plD_init_vga()
  98. *
  99. * Initialize device.
  100. \*----------------------------------------------------------------------*/
  101.  
  102. void
  103. plD_init_vga(PLStream *pls)
  104. {                               /* ~~~~ */
  105. #if !(_MSC_VER < 700)
  106.   struct _videoconfig vcfg;
  107. #endif
  108.  
  109.   pls->termin = 1;              /* is an interactive terminal */
  110.   pls->icol0 = 1;
  111.   pls->width = 1;
  112.   pls->bytecnt = 0;
  113.   pls->page = 0;
  114.   pls->graphx = FALSE;  /* assume not in graphics mode (ie. text mode) */
  115.   if (!pls->colorset)
  116.     pls->color = 1;
  117.  
  118. #if (_MSC_VER >= 700)
  119.   _setvideomode( _MAXRESMODE );       /* try for max resolution */
  120.   _getvideoconfig( &vcfg );           /* get the new setup */
  121.   if ( vcfg.numcolors < 16 ) {          /* 16 colours ? */
  122.     if ( !_setvideomode(_VRES16COLOR) ) {       /* try for 16 colours ? */
  123.       fputs("Unable to set graphics mode.", stderr);
  124.       exit(0);
  125.     }
  126.     _getvideoconfig( &vcfg );         /* got something */
  127.   }
  128.  
  129.   DetectedVideoMode = vcfg.mode;
  130.   vgaXres = vcfg.numxpixels -1;
  131.   vgaYres = vcfg.numypixels -1;
  132. #else   /* (_MSC_VER >= 700) */
  133.   if ( !_setvideomode(_VRES16COLOR) ) {         /* try for 16 colours ? */
  134.     fputs("Unable to set graphics mode.", stderr);
  135.     exit(0);
  136.   }
  137.   DetectedVideoMode = _VRES16COLOR;
  138.   vgaXres = 640 -1;
  139.   vgaYres = 480 -1;
  140. #endif  /* (_MSC_VER >= 700) */
  141.   pls->graphx = TRUE;
  142.   isPageDirty = FALSE;
  143.  
  144. /* Set up device parameters */
  145.   plP_setpxl(2.5, 2.5); /* My best guess.  Seems to work okay. */
  146.  
  147.   plP_setphy((PLINT) 0, (PLINT) vgaXres, (PLINT) 0, (PLINT) vgaYres );
  148. }
  149.  
  150. /*----------------------------------------------------------------------*\
  151. * plD_line_vga()
  152. *
  153. * Draw a line in the current color from (x1,y1) to (x2,y2).
  154. \*----------------------------------------------------------------------*/
  155.  
  156. void
  157. plD_line_vga(PLStream *pls, short x1a, short y1a, short x2a, short y2a)
  158. {                               /* ~~~~ */
  159.   isPageDirty = TRUE;
  160.   _moveto( (short) x1a, (short) (vgaYres - y1a) );
  161.   _lineto( (short) x2a, (short) (vgaYres - y2a) );
  162. }
  163.  
  164. /*----------------------------------------------------------------------*\
  165. * plD_polyline_vga()
  166. *
  167. * Draw a polyline in the current color.
  168. \*----------------------------------------------------------------------*/
  169.  
  170. void
  171. plD_polyline_vga(PLStream *pls, short *xa, short *ya, PLINT npts)
  172. {                               /* ~~~~ */
  173.   register PLINT i;
  174.  
  175.   isPageDirty = TRUE;
  176.   _moveto( (short) xa[0], (short) (vgaYres - ya[0]) );
  177.   for ( i = 1; i < npts; i++ )
  178.     _lineto( (short) xa[i], (short) (vgaYres - ya[i]) );
  179. }
  180.  
  181. /*----------------------------------------------------------------------*\
  182. * plD_eop_vga()
  183. *
  184. * End of page.
  185. \*----------------------------------------------------------------------*/
  186.  
  187. void
  188. plD_eop_vga(PLStream *pls)
  189. {                               /* ~~~~ */
  190.   if ( isPageDirty == TRUE )
  191.     pause(pls);
  192. #if ( _MSC_VER < 700 )
  193.   _eopscreen(_GCLEARSCREEN);    /* did this _ever_ work? */
  194. #else
  195.   _clearscreen( _GCLEARSCREEN );
  196. #endif
  197.   isPageDirty = FALSE;
  198. }
  199.  
  200. /*----------------------------------------------------------------------*\
  201. * plD_bop_vga()
  202. *
  203. * Set up for the next page.
  204. * Advance to next family file if necessary (file output).
  205. \*----------------------------------------------------------------------*/
  206.  
  207. void
  208. plD_bop_vga(PLStream *pls)
  209. {                               /* ~~~~ */
  210.   pls->page++;
  211.   plD_eop_vga(pls);
  212. }
  213.  
  214. /*----------------------------------------------------------------------*\
  215. * plD_tidy_vga()
  216. *
  217. * Close graphics file or otherwise clean up.
  218. \*----------------------------------------------------------------------*/
  219.  
  220. void
  221. plD_tidy_vga(PLStream *pls)
  222. {                               /* ~~~~ */
  223.   vga_text(pls);
  224.   pls->page = 0;
  225.   pls->OutFile = NULL;
  226. }
  227.  
  228. /*----------------------------------------------------------------------*\
  229. * plD_state_vga()
  230. *
  231. * Handle change in PLStream state (color, pen width, fill attribute, etc).
  232. \*----------------------------------------------------------------------*/
  233.  
  234. void
  235. plD_state_vga(PLStream *pls, PLINT op)
  236. {                               /* ~~~~ */
  237.   switch (op) {
  238.  
  239.   case PLSTATE_WIDTH:
  240.     break;
  241.  
  242.   case PLSTATE_COLOR0:{
  243.     static long cmap[16] = {
  244.         _WHITE, _RED, _LIGHTYELLOW, _GREEN,
  245.         _CYAN, _WHITE, _WHITE, _GRAY,
  246.         _WHITE, _BLUE, _GREEN, _CYAN,
  247.         _RED, _MAGENTA, _LIGHTYELLOW, _WHITE
  248.         };
  249.  
  250.     if (pls->icol0 < 0 || pls->icol0 > 15)
  251.         pls->icol0 = 15;
  252.  
  253.     _remappalette((short) pls->icol0, cmap[pls->icol0]);
  254.     _setcolor((short) pls->icol0);
  255.     break;
  256.   }
  257.  
  258.   case PLSTATE_COLOR1:
  259.     break;
  260.   }
  261. }
  262.  
  263. /*----------------------------------------------------------------------*\
  264. * plD_esc_vga()
  265. *
  266. * Escape function.
  267. \*----------------------------------------------------------------------*/
  268.  
  269. void
  270. plD_esc_vga(PLStream *pls, PLINT op, void *ptr)
  271. {                               /* ~~~~ */
  272.   switch (op) {
  273.   case PLESC_TEXT:
  274.     vga_text(pls);
  275.     break;
  276.  
  277.   case PLESC_GRAPH:
  278.     vga_graphics(pls);
  279.     break;
  280.   }
  281. }
  282.  
  283. /*----------------------------------------------------------------------*\
  284. * vga_text()
  285. *
  286. * Switch to text mode.
  287. \*----------------------------------------------------------------------*/
  288.  
  289. static void
  290. vga_text(PLStream *pls)
  291. {                               /* ~~~~ */
  292.   if ( pls->graphx ) {
  293.     if ( isPageDirty == TRUE )
  294.       pause(pls);
  295.     _setvideomode(_DEFAULTMODE);
  296.     pls->graphx = FALSE;
  297.   }
  298. }
  299.  
  300. /*----------------------------------------------------------------------*\
  301. * vga_graphics()
  302. *
  303. * Switch to graphics mode.
  304. \*----------------------------------------------------------------------*/
  305.  
  306. static void
  307. vga_graphics(PLStream *pls)
  308. {                               /* ~~~~ */
  309.   if ( !pls->graphx ) {
  310.     if (!_setvideomode( DetectedVideoMode )) {
  311.       fputs("Unable to set graphics mode.", stderr);    /* shouldn't happen */
  312.       exit(0);
  313.     }
  314.     pls->graphx = TRUE;
  315.     isPageDirty = FALSE;
  316.   }
  317. }
  318.  
  319. /*----------------------------------------------------------------------*\
  320. * pause()
  321. *
  322. * Wait for a keystroke.
  323. \*----------------------------------------------------------------------*/
  324.  
  325. static void
  326. pause(PLStream *pls)
  327. {
  328.     if (pls->nopause)
  329.     return;
  330.  
  331.     _settextposition(0, 0);
  332.     _outtext("pause->");
  333.     while ( !_getch() );
  334. }
  335.  
  336. #else
  337. int
  338. pldummy_mscvga()
  339. {                               /* ~~~~ */
  340.   return 0;
  341. }
  342.  
  343. #endif                          /* (_MSC_VER) && (MSDOS) */
  344. /* ///////////////////// end of file (c source) /////////////////// */
  345.